package com.imm.da.main.weather.model

import android.util.Log
import com.alibaba.fastjson2.JSON
import com.imm.da.base.vm.BaseViewModel
import com.imm.da.bean.Image
import com.imm.da.bean.ImgResult
import com.imm.net.http.weather.WeatherService

/**
 * <p>------------------------------------------------------
 * <p> Copyright (C) 2021 zhangmz, All rights reserved.
 * <p> If there is technical discussion, you can contact zhangmz90@foxmail.com
 * <p>------------------------------------------------------
 * <p> des
 * <p>
 *
 * @author Created by zhangmz
 * @date on 2021/12/4
 */
class WeatherViewModel : BaseViewModel() {

    private val service = WeatherService()

    fun queryImage(
        key: String?,
        success: (Image) -> Unit,
        failure: () -> Unit = {  }
    ){
        if (key.isNullOrEmpty()){
            Log.e("aaaaa", "query image keyword can not be null")
            failure()
            return
        }
        service.queryImg(
            keyword = key,
            success = {
                Log.e("aaaaa", "query image result:$it")

//                val result = JSON.parseObject(it?.toJSONString(), ImgResult::class.java)
//                Log.v("aaaaa", "queryImage, size:${result.list?.size}")
//                success(result.list?.get(0)?: return@queryImg)
            },
            failure = {
                Log.v("aaaaa", "queryImage, error:$it")
            }
        )
    }

}